package rs.dalao.syc.doctor.all.dao.persist.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import rs.dalao.syc.doctor.all.dao.persist.mapper.DoctorMapper;
import rs.dalao.syc.doctor.all.dao.persist.repository.IDoctorRepository;
import rs.dalao.syc.doctor.all.pojo.entity.Doctor;
import rs.dalao.syc.doctor.all.pojo.param.DoctorUpdateParam;
import rs.dalao.syc.doctor.all.pojo.vo.DoctorInfoVO;
import rs.dalao.syc.doctor.all.pojo.vo.UserPersonalListVO;

@Repository
public class DoctorRepositoryImpl implements IDoctorRepository {
    @Autowired
    private DoctorMapper doctorMapper;
    //跟新医生的个人资料
    @Override
    public int updateDoctorInfo(DoctorUpdateParam doctorUpdateParam, Long id) {
        UpdateWrapper<Doctor> queryWrapper = new UpdateWrapper<>();
        queryWrapper.eq("id",id)
                .set("avatar",doctorUpdateParam.getAvatar())
                .set("department",doctorUpdateParam.getDepartment())
                .set("hospital",doctorUpdateParam.getHospital())
                .set("phone",doctorUpdateParam.getPhone());
        /*QueryWrapper<Doctor> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);*/
        Doctor doctor = new Doctor();
        BeanUtils.copyProperties(doctorUpdateParam,doctor);
        return doctorMapper.update(doctor,queryWrapper);
    }

    @Override
    public DoctorInfoVO selectById(Long id) {
        return doctorMapper.selectInfoById(id);
    }

    @Override
    public UserPersonalListVO selectUserInfoByUsername(String userName) {
        return doctorMapper.selectUserInfoByUsername(userName);
    }
}
